package fw.asmx.materialdesign;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class TestFragment extends Fragment
{
    private RecyclerView rv;

    private List<String> lst;

    @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                                 Bundle savedInstanceState)
    {
        rv = new RecyclerView(getActivity());
        rv.setHasFixedSize(true);
        rv.setLayoutManager(new LinearLayoutManager(getActivity()));

        lst = new ArrayList<>();
        for (int i = 0; i < 500; i++)
        {
            lst.add("No. " + i);
        }

        rv.setAdapter(new RecyclerView.Adapter<ViewHolder>()
        {
            @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
            {
                View v = new TextView(getActivity());
                return new ViewHolder(v);
            }

            @Override public void onBindViewHolder(ViewHolder vh, int position)
            {
                vh.tv.setText(lst.get(position));
            }

            @Override public int getItemCount()
            {
                return lst.size();
            }
        });
        return rv;
    }

    class ViewHolder extends RecyclerView.ViewHolder
    {
        public TextView tv;

        public ViewHolder(View v)
        {
            super(v);
            tv = (TextView) v;
        }
    }
}
